<template>
  <el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="name" label="姓名" width="100" />
    <el-table-column prop="phone" label="电话">
      <template #default="{ row }">
        <span>
          {{ row.phone || "-" }}
        </span>
      </template>
    </el-table-column>
    <el-table-column prop="day" label="阳寿" />
    <el-table-column prop="birthday" label="生辰八字" />
    <el-table-column prop="status" label="状态">
      <template #default="{ row }">
        <span>
          {{ row.status == 1 ? "正常" : "死亡" }}
        </span>
      </template>
    </el-table-column>
    <el-table-column prop="create_time" label="创建时间" />
    <el-table-column label="操作">
      <template #default="{ row }">
        <el-button type="text" @click="handleEdit(row)">修改</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :total="num"
    ></el-pagination>
  </div>
  <Dialog ref="addInfo" />
</template>
<script>
import { ref, reactive, toRefs, onMounted } from "vue";
import Dialog from "./drawer.vue";
import axios from "@/utils/axios";
export default {
  components: {
    Dialog,
  },
  props: {
    searchInfo: Object,
  },
  setup(props) {
    const addInfo = ref(null);
    const state = reactive({
      tableData: [],
      num: 0,
      currentPage: 1,
    });
    onMounted(() => {
      getData();
    });
    const getData = () => {
      let httpOption = axios.post;
      let params = {
        ...props.searchInfo,
        page: state.currentPage,
      };
      httpOption("/api/admin/users", params).then((res) => {
        state.tableData = res.data;
        state.num = res.meta.total;
      });
    };
    const handleCurrentChange = (e) => {
      state.currentPage = e;
      getData();
    };
    const handleEdit = (row) => {
      addInfo.value.open("edit", row);
    };
    return {
      addInfo,
      handleEdit,
      getData,
      handleCurrentChange,
      ...toRefs(state),
    };
  },
};
</script>
<style lang='scss' scoped>
</style>